import { ApplyModel, GroupModel, ReplyModel } from "/@/api/model/groupModel";
import { defHttp } from "/@/utils/http/axios";
import { UserModel } from "/@/api/model/userModel";
import { PageParams, PageResult, PageWithId } from "/@/api/model/pageModel";

enum Api {
  GetGroupPage = "/group/page",
  GetApplyList = "/group/applyList",
  GetReplyList = "/group/replyList",
  GetSelectList = "/group/selectList",
  GetUserListByTutor = "/group/list/tutor",
  GetUserListByCaptain = "/group/list/captain",
  ApplyGroup = "/group/apply",
  AgreeApplication = "/group/agree",
  RejectApplication = "/group/reject",
  BindCaptain = "/group/bindCaptain",
  DumpCaptain = "/group/dumpCaptain",
  SaveDefault = "/group/save/default",
  SavePractical = "/group/save/practical",
  UpdateGroup = "/group/update",
  RemoveGroup = "/group/remove",
}

export const getGroupPageApi = (params: PageParams) =>
  defHttp.get<PageResult<GroupModel>>({ url: Api.GetGroupPage, params });

export const getGroupPageByUserIdApi = (params: PageWithId) =>
  defHttp.get<PageResult<GroupModel>>({ url: `${Api.GetGroupPage}/${params.groupId}`, params });

export const getApplyListApi = (params: PageParams) =>
  defHttp.get<PageResult<ApplyModel>>({ url: Api.GetApplyList, params });

export const getReplyListApi = (params: PageParams) =>
  defHttp.get<PageResult<ReplyModel>>({ url: Api.GetReplyList, params });

export const getSelectListApi = () => defHttp.get<GroupModel[]>({ url: Api.GetSelectList });

export const getUserListByTutorApi = (params: PageWithId) =>
  defHttp.get<PageResult<UserModel>>({
    url: `${Api.GetUserListByTutor}/${params.groupId}`,
    params,
  });

export const getUserListByCaptainApi = (params: PageParams) =>
  defHttp.get<PageResult<UserModel>>({ url: Api.GetUserListByCaptain, params });

export const applyGroupApi = (groupId: number, reason?: string) =>
  defHttp.post<void>({ url: Api.ApplyGroup, params: { groupId, reason } });

export const agreeApplicationApi = (userId: number, groupId: number) =>
  defHttp.put<void>({ url: `${Api.AgreeApplication}/${userId}/${groupId}` });

export const rejectApplicationApi = (userId: number, groupId: number) =>
  defHttp.delete<void>({ url: `${Api.RejectApplication}/${userId}/${groupId}` });

export const bindCaptainApi = (userId: number, groupId: number) =>
  defHttp.post<void>({ url: `${Api.BindCaptain}/${userId}/${groupId}` });

export const dumpCaptainApi = (userId: number, groupId: number) =>
  defHttp.delete<void>({ url: `${Api.DumpCaptain}/${userId}/${groupId}` });

export const saveDefaultGroupApi = (params: GroupModel) =>
  defHttp.post<void>({ url: Api.SaveDefault, params });

export const savePracticalGroupApi = (params: GroupModel) =>
  defHttp.post<void>({ url: Api.SavePractical, params });

export const updateGroupApi = (params: GroupModel) =>
  defHttp.put<void>({ url: Api.UpdateGroup, params });

export const removeGroupApi = (groupId: number) =>
  defHttp.delete<void>({ url: `${Api.RemoveGroup}/${groupId}` });
